package io;

import java.io.*;
import java.util.Scanner;

/**
 * 在流连接中使用PrintWriter
 */
public class PWDemo2 {
    public static void main(String[] args) throws FileNotFoundException {
        FileOutputStream fos = new FileOutputStream("pw2.txt",true);
        OutputStreamWriter osw = new OutputStreamWriter(fos);
        BufferedWriter bw = new BufferedWriter(osw);
        PrintWriter pw = new PrintWriter(bw,true);//true 相当于flush功能
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入：");
        while (true){
            String a = scan.nextLine();
            String b = "exit";
            if (a.equalsIgnoreCase(b)){
                break;
            }
            pw.println(a);
            pw.flush();
        }
        System.out.println("运行完毕");
        pw.close();
    }
}
